package ${webPackageName}.test;


import java.util.Arrays;

import org.junit.Assert;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import ${commonPackageName}.entity.page.PageInfo;
import ${webPackageName}.WebApplication;
import ${servicePackageName}.qo.other.BatchDeleteQo;
import ${servicePackageName}.qo.sys.UserListPageReq;
import ${servicePackageName}.qo.sys.UserReq;

/**
 * 用户controller单元测试
 * @author lizihao
 *
 */
<#noparse>
@RunWith(SpringRunner.class)
@SpringBootTest(classes = WebApplication.class)
@WebAppConfiguration
@Transactional(rollbackFor = Exception.class)
public class SysUserControllerTest extends TestFoo{
	
	private final String BASE_REQUEST_MAPPING = "/base/sysUser";
	
	/**
	 * 用户列表(单元测试)
	 * @throws Exception
	 */
	@org.junit.Test
	public void testPageUser() throws Exception {	
		MvcResult result =  mvc.perform(MockMvcRequestBuilders.
				post(BASE_REQUEST_MAPPING+"/page").
				header("Access-Control-Allow-Headers", "Cache-Control, Origin, X-Requested-With,Content-Type,catalogType,Accept,Authorization,token,Content-Disposition,Content-Length,Date,X-Request-Id").
				header("Origin","*").
				header("isTest", "true").
				header("Authorization", header).
				contentType(MediaType.APPLICATION_JSON_VALUE).
				content(JSON.toJSONString(
						new UserListPageReq().setPageInfo(new PageInfo().setPageNum(1L).setPageSize(10L))
						))
				).andReturn();
		Assert.assertEquals(0,JSONObject.parseObject(result.getResponse().getContentAsString()).getJSONObject("result").getIntValue("resultCode"));
	}
	
	/**
	 * 用户信息(单元测试)
	 * @throws Exception
	 */
	@org.junit.Test
	public void testInfoUser() throws Exception {	
		MvcResult result =  mvc.perform(MockMvcRequestBuilders.
				post(BASE_REQUEST_MAPPING+"/info").
				header("Access-Control-Allow-Headers", "Cache-Control, Origin, X-Requested-With,Content-Type,catalogType,Accept,Authorization,token,Content-Disposition,Content-Length,Date,X-Request-Id").
				header("Origin","*").
				header("isTest", "true").
				header("Authorization", header).
				contentType(MediaType.APPLICATION_JSON_VALUE).
				param("id", "2")
				).andReturn();
		Assert.assertEquals(0,JSONObject.parseObject(result.getResponse().getContentAsString()).getJSONObject("result").getIntValue("resultCode"));
	}
	
	/**
	 * 删除用户用户(单元测试)
	 * @throws Exception
	 */
	@org.junit.Test
	public void testdeleteUser() throws Exception {	
		MvcResult result =  mvc.perform(MockMvcRequestBuilders.
				post(BASE_REQUEST_MAPPING+"/delete").
				header("Access-Control-Allow-Headers", "Cache-Control, Origin, X-Requested-With,Content-Type,catalogType,Accept,Authorization,token,Content-Disposition,Content-Length,Date,X-Request-Id").
				header("Origin","*").
				header("isTest", "true").
				header("Authorization", header).
				contentType(MediaType.APPLICATION_JSON_VALUE).
				content(JSON.toJSONString(
						new BatchDeleteQo().setIds(Arrays.asList("2"))
						))
				).andReturn();
		Assert.assertEquals(0,JSONObject.parseObject(result.getResponse().getContentAsString()).getJSONObject("result").getIntValue("resultCode"));
	}
	
	/**
	 * 新增或修改用户(单元测试)
	 * @throws Exception
	 */
	@org.junit.Test
	public void testAddUser() throws Exception {	
		MvcResult result =  mvc.perform(MockMvcRequestBuilders.
				post(BASE_REQUEST_MAPPING+"/addOrUpdate").
				header("Access-Control-Allow-Headers", "Cache-Control, Origin, X-Requested-With,Content-Type,catalogType,Accept,Authorization,token,Content-Disposition,Content-Length,Date,X-Request-Id").
				header("Origin","*").
				header("isTest", "true").
				header("Authorization", header).
				contentType(MediaType.APPLICATION_JSON_VALUE).
				content(JSON.toJSONString(
						new UserReq().setUserAccount("junittest").setUserName("junit")
						))
				).andReturn();
		Assert.assertEquals(0,JSONObject.parseObject(result.getResponse().getContentAsString()).getJSONObject("result").getIntValue("resultCode"));
	}
	
	
}
</#noparse>